import { defineStore } from 'pinia';
import { getUserInfo } from '@/api/login';
import { getUserId } from "@/utils/auth.ts";

export default defineStore('user', {
  state: () => {
    return {
      orderInfo: {},
      filesInfo: {},
      taskInfo: {},
      userName: null
    }
  },
  actions: {
    setOrder(params: any) {
      return new Promise((resolve, reject) => {
        this.orderInfo = params;
        resolve(true);
      })
    },
    setFiles(params: any) {
      return new Promise((resolve, reject) => {
        this.filesInfo = params;
        resolve(true);
      })
    },
    setTask(params: any) {
      return new Promise((resolve, reject) => {
        this.taskInfo = params;
        resolve(true);
      })
    },
    setUser() {
      return new Promise((resolve, reject) => {
        getUserInfo({createGlobalUserId:getUserId()}).then((res: any) => {
          if (res) {
            this.userName = res;
            resolve(true);
          }
        })
      })
    }
  }
})